package com.llt.ai.service.impl;

import com.llt.ai.dto.Result;
import com.llt.ai.entity.Booking;
import com.llt.ai.enums.BookingStatus;
import com.llt.ai.mapper.BookingMapper;
import com.llt.ai.service.IBookingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author llt
 * @since 2025-08-03
 */
@Service
@RequiredArgsConstructor
public class BookingServiceImpl extends ServiceImpl<BookingMapper, Booking> implements IBookingService {

    @Override
    public Result getBookingDetail(String bookingNumber, String name) {
        Booking booking = this.lambdaQuery()
                .eq(Booking::getBookingNumber, bookingNumber)
                .eq(Booking::getCustomerName, name)
                .one();
        Result result = new Result();
        BeanUtils.copyProperties(booking, result);
        return result;
    }

    @Override
    public boolean cancelBooking(String bookingNumber, String name) {
        // 这里就不检验了
        boolean update = this.lambdaUpdate()
                .eq(Booking::getBookingNumber, bookingNumber)
                .eq(Booking::getCustomerName, name)
                .set(Booking::getBookingStatus, BookingStatus.CANCELLED)
                .update();
        return update;
    }
}
